#!/usr/bin/env python
# encoding: utf-8
'''
@author: wangjianrong
@software: pycharm
@file: imgs2video.py
@time: 2020/9/25 17:21
@desc:
'''

from opencv_op.my_videowriter import MyVideoWriter
from opencv_op.read_img import cv_imread
import os
import cv2


#修改此处文件夹路径
root_folder = 'F:/新建文件夹/烟雾1'


image_folder = root_folder + '/image/'
label_folder = root_folder + '/label/'
video_name = os.path.basename(root_folder) + '.mp4'
save_path = os.path.join(root_folder,video_name)

list_imgs = os.listdir(image_folder)
list_imgs.sort()
vw = MyVideoWriter(save_path)
for img_name in list_imgs:
    labelname = os.path.splitext(img_name)[0] + '.txt'
    label_path = label_folder + labelname
    img_path = image_folder + img_name
    img = cv_imread(img_path)
    with open(label_path,'r') as f:
        for line in f.readlines():
            line = line.strip().split(',')
            xmin,ymin,xmax,ymax = map(int,line)
            cv2.rectangle(img,(xmin,ymin),(xmax,ymax),(0,0,255),3)
    vw.save(img)
vw.release()